#ifndef LEVELMAP_H_
#define LEVELMAP_H_

#include "StatefulUnit.h"
#include "Vector2df.h"
#include "Vector2di.h"
#include "BackgroundImage.h"

#include "userStates.h"     // Make sure your state is listed in this include.
#ifdef _DEBUG
#include "Text.h"
#include "Pixel.h"
#endif
#include "AnimatedSprite.h"
//#include "TileMap.h"
#include "Physics.h"
#include "NumberUtility.h"
#include "StringUtility.h"
#include "Decryptor.h"
#include <sys/stat.h>
#include <fstream>

#include <string>
#include <map>
#include <vector>
#include <list>
#include <deque>
#include "BaseUnit.h"
#include "Overlay.h"
#include "Sequence.h"

using namespace StringUtility;

class LevelMap : public WandorBaseState
{
    public:
        LevelMap();
        LevelMap(string password);
        LevelMap(string fileName, string password);
        virtual ~LevelMap();

        virtual void render(SDL_Surface *screen);
        virtual void update();
        //virtual void update();

        virtual void userInput();
        virtual void pauseInput();

        string GetFileName() {return fileName;}
        void SetPassword(string password);
        void LoadLevelMap(string fileName);
        void LoadLevelMapFromWString(wstring file);
        void LoadLevelMapFromWStringVersioned(wstring file);
        void Activate();
        void ReActivate();

        vector< Overlay* >* GetOverlays() {return &overlays;};
        Overlay* GetOverlay(CRuint index) {return overlays.at(index);};
        int OverlayCount() {return overlays.size();};
        const SimpleJoy* GetInput() const {return input;};

        void GoToLevel(string levelFileName);
        void AddOverlay(Overlay *overlay);
        void RemoveOverlay(Overlay *overlay);
        void AddEffect(StatefulUnit *effect);
        void AddEffect(string effectName, string stateName, const Vector2df p);
        void RemoveEffect(StatefulUnit *effect);
        BaseUnit *SetState(string unitName, string stateName);
        void StartSequence(string sequenceName);
        void SequenceDone();
    protected:
    	void init();
    	bool FileExists(string fileName);
    	bool getLine(wstring temp, wstring& line, uint& currentPos);
		Vector2di GetCenterPosition(Vector2df Pos, Vector2df Size);
		void startSequenceReal(string sequenceName);

        string fileName;
        Decryptor *decryptor;
        string levelMapName;
        string initialSequence;
        uint transparent;
        uint mapWidth;
        uint mapHeight;
        vector<Overlay *> overlays;
        vector<BackgroundImage *> backgroundImages;
        vector<Sequence *> sequences;
        deque<string> sequenceStarts;
        bool sequenceRunning;
        list<StatefulUnit *> effects; // these will constantly be added and removed, so use a list
        #ifdef _DEBUG
        Text debugPrint;
        Pixel pix;
        #endif
};

#endif /*LEVELMAP_H_*/
